package com.valsong.sandbox.mock;

import com.alibaba.jvm.sandbox.api.ModuleLifecycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.util.Map;

/**
 * Mocker
 *
 * @author Val Song
 */
public interface Mocker extends ModuleLifecycle {

    Logger log = LoggerFactory.getLogger(Mocker.class);

    /**
     * mock模块入口
     *
     * @param param
     * @param printWriter
     */
    void mock(Map<String, String> param, PrintWriter printWriter);

    /**
     * 模块名称
     */
    String moduleName();


    @Override
    default void onLoad() throws Throwable {
        log.info("====== SandBox Module [{}] load! ======", moduleName());
    }

    @Override
    default void onUnload() throws Throwable {
        log.info("====== SandBox Module [{}] unload! ======", moduleName());

    }

    @Override
    default void onActive() throws Throwable {
        log.info(">>>>>> SandBox Module [{}] active! >>>>>>", moduleName());
    }

    @Override
    default void onFrozen() throws Throwable {
        log.info("<<<<<< SandBox Module [{}] frozen! <<<<<<", moduleName());
    }

    @Override
    default void loadCompleted() {
        log.info("====== SandBox Module [{}] loadCompleted! ======", moduleName());
    }

}
